package org.example.iris.controller;

import org.example.iris.dto.Result;
import org.example.iris.entity.UploadLog;
import org.example.iris.entity.User;
import org.example.iris.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    AdminService adminService;

    //处理企业注册申请
    @PutMapping("/handle")
    public Result handle(int adminId, int companyId, String status) {
        if (status.equals("accept")){
            adminService.acceptCompanyRegistration(adminId,companyId);
            return Result.success();
        }
        else{
            adminService.rejectCompanyRegistration(adminId,companyId);
            return Result.success();
        }
    }

    //编辑用户信息(用户名)
    @PutMapping("/modifyUser")
    public Result modifyUser(@RequestBody User user) {
        adminService.modifyUser(user);
        return Result.success();
    }

    //删除用户
    @DeleteMapping("/deleteUser")
    public Result deleteUser(int userId) {
        adminService.deleteUser(userId);
        return Result.success();
    }

    //查看所有上传记录
    @GetMapping("/viewUploadRecords")
    public Result<List<UploadLog>> viewUploadRecords() {
        return Result.success(adminService.viewUploadRecords());
    }
}
